package Song.Han.demo04;

import java.util.HashMap;
import java.util.Scanner;

/*  题目：
 *   计算一个字符串每个字符出现的次数
 * */
public class Demo04Tset {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = sc.next();
        charCount(str);
    }

    private static void charCount(String str) {
        HashMap<Character, Integer> map = new HashMap<>();
        for (char chars : str.toCharArray()) {
            if (map.containsKey(chars)) {
                Integer value = map.get(chars);
                value++;
                map.put(chars,value);
            }
            else
                map.put(chars,1);
        }
        for(Character chars: map.keySet()){
            Integer value = map.get(chars);
            System.out.println(chars+":"+value+"个");
        }
    }
}
